package model

import (
	"database/sql/driver"
	"encoding/json"
	"github.com/shopspring/decimal"
)

type ShopStatisticsOld struct {
	Account
	MerchantCount              MerchantCount              `json:"merchantCount" bson:"-"`
	OrderStatusCountForSummary OrderStatusCountForSummary `json:"orderStatusCountForSummary" bson:"-"`
	OfficialMessage            OfficialMessage            `json:"officialMessage" bson:"-"`
	ShopData                   ShopData                   `json:"shopData" bson:"-"`
	AfterSalePre               int                        `json:"after_sale_pre" bson:"-"`
	AfterSaleCurrent           int                        `json:"after_sale_current" bson:"-"`
}

func (ShopStatistics) TableName() string {
	return "shop_statistics"
}

type ShopStatistics struct {
	ShopId                    uint            `json:"shop_id"`
	Online                    uint            `json:"online"`
	YesterdayViewCount        uint            `json:"yesterday_view_count"`
	NegativeOdr               decimal.Decimal `json:"negative_odr"`
	NegativeCommentCount      uint            `json:"negative_comment_count"`
	CommentCount              uint            `json:"comment_count"`
	NegativeCommentTotal      uint            `json:"negative_comment_total"`
	CommentTotal              uint            `json:"comment_total"`
	LackOdr                   decimal.Decimal `json:"lack_odr"`
	TransFlag                 int             `json:"trans_flag"`
	TransAt                   string          `json:"trans_at"`
	TransTimes                uint            `json:"trans_times"`
	CancelCount               uint            `json:"cancel_count"`
	PreAfterSaleCount         uint            `json:"pre_after_sale_count"`
	CAfterSaleCount           uint            `json:"c_after_sale_count"`
	AfterSaleCost             decimal.Decimal `json:"after_sale_cost"`
	CtmItemViewPvSevenDays    uint            `json:"ctm_item_view_pv_seven_days"`
	CartItemNumSevenDays      uint            `json:"cart_item_num_seven_days"`
	ItemVerifiedUvSevenDays   uint            `json:"item_verified_uv_seven_days"`
	ItemVerifiedCntSevenDays  uint            `json:"item_verified_cnt_seven_days"`
	ItemVerifiedCntThirtyDays uint            `json:"item_verified_cnt_thirty_days"`
	CtmItemViewPvThirtyDays   uint            `json:"ctm_item_view_pv_thirty_days"`
	CartItemNumThirtyDays     uint            `json:"cart_item_num_thirty_days"`
	ItemVerifiedUvThirtyDays  uint            `json:"item_verified_uv_thirty_days"`
	ItemViewThirtyDays        uint            `json:"item_view_thirty_days"`
	LimitFlag                 uint            `json:"limit_flag"`
	MerchantNotItemCode       uint            `json:"merchant_not_item_code"`
	MerchantNew               uint            `json:"merchant_new"`
}

func (ShopSaleStatistics) TableName() string {
	return "shop_sale_statistics"
}

type ShopSaleStatistics struct {
	ShopId               uint            `json:"shop_id"`
	Forfeit              decimal.Decimal `json:"forfeit"`
	Yesterday            decimal.Decimal `json:"yesterday"`
	TodayBeforeYesterday decimal.Decimal `json:"today_before_yesterday"`
	GrandTotal           decimal.Decimal `json:"grand_total"`
	AvgDaily             decimal.Decimal `json:"avg_daily"`
	PctChange            decimal.Decimal `json:"pct_change"`
}

func (ShopItemSaleStatistics) TableName() string {
	return "item_sale_statistics"
}

type ShopItemSaleStatistics struct {
	ShopId           uint            `json:"shop_id"`
	ItemID           uint            `json:"item_id"`
	GrandTotal       decimal.Decimal `json:"grand_total"`
	ItemsTotal       decimal.Decimal `json:"items_total"`
	SkuImageUrl      string          `json:"sku_image_url"`
	OrderCount       uint            `json:"order_count"`
	PerCustomerPrice decimal.Decimal `json:"per_customer_price"`
	ItemTitle        string          `json:"item_title"`
	ItemNo           string          `json:"item_no"`
	OverTime         int             `json:"over_time"`
	Trend            Trend           `json:"trend" gorm:"comment:7日涨跌"`
}

//type Trend struct {
//	GrandTotal      decimal.Decimal `json:"grand_total"`
//	ItemsTotal      decimal.Decimal `json:"items_total"`
//	PlacesOrderDate string          `json:"places_order_date"`
//}

type Trend []interface{}

func (t Trend) Value() (driver.Value, error) {
	b, err := json.Marshal(t)
	return b, err
}

func (t *Trend) Scan(input interface{}) error {
	return json.Unmarshal(input.([]byte), t)
}
